package com.example.demo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.example.demo.MainActivity;
import com.example.demo.R;

public class ResultActivity extends AppCompatActivity implements View.OnClickListener {

    private static final int CODE_FOR_RESULT = 2;
    /**
     * 回复 :MainActivity
     */
    private Button btn_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);
        initView();
    }

    private void initView() {
        btn_back = (Button) findViewById(R.id.btn_back);
        btn_back.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
case R.id.btn_back:
    Log.i(MainActivity.TAG, getIntent().getStringExtra("msg"));
    Intent intent = new Intent();
    intent.putExtra("result", "收到，我是ResultActivity");
    setResult(CODE_FOR_RESULT, intent);
    finish();
    break;
        }
    }
}